//
//  SYFunctionTableViewCell.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/11.
//  Copyright © 2019年 李文强. All rights reserved.
//

#import "SYFunctionTableViewCell.h"

@interface SYFunctionTableViewCell ()

@property (strong, nonatomic) UIView *allView;//全部
@property (strong, nonatomic) UIImageView *picImage;//图片
@property (strong, nonatomic) UILabel *titleLab;//标题
@property (strong, nonatomic) UIImageView *pictureView;//图片
@property (strong, nonatomic) UIView *bgImageView;


@end




@implementation SYFunctionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self initSubView];
        [self initLayout];
    }
    return self;
}

- (void)initSubView {
    [self addSubview:self.allView];
    [self.allView addSubview:self.picImage];
    [self.allView addSubview:self.titleLab];
    [self addSubview:self.bgImageView];
    [self addSubview:self.pictureView];
}

- (void)initLayout {
    [self.allView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.left.equalTo(self);
    }];
    [self.picImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-40);
        make.centerY.equalTo(self.mas_centerY);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.picImage.mas_right).offset(10);
    }];
    
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.equalTo(self);
    }];
    
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self);
        make.width.height.mas_equalTo(44);
    }];
    
}

- (void)setFunction:(SYFunctoinModel *)function {
    if (function.isFolding) {//折叠
        _bgImageView.hidden = NO;
        _allView.hidden = YES;
        _pictureView.hidden = NO;
        _pictureView.image = [UIImage imageNamed:function.imageName];
        if (function.isBg) {
            _bgImageView.backgroundColor = [UIColor colorWithHexString:@"#DDDDDD"];
        } else {
            _bgImageView.backgroundColor = [UIColor clearColor];
        }
    } else {
        _bgImageView.hidden = YES;
        _allView.hidden = NO;
        _pictureView.hidden = YES;
        _picImage.image = [UIImage imageNamed:function.imageName];
        _titleLab.text = function.titleName;
        if (function.isBg) {
            _allView.backgroundColor = [UIColor colorWithHexString:@"#DDDDDD"];
        } else {
            _allView.backgroundColor = [UIColor clearColor];
        }
    }
}


#pragma mark - set
- (UIView *)allView {
    if (!_allView) {
        _allView = [[UIView alloc] init];
    }
    return _allView;
}
- (UIImageView *)picImage {
    if (!_picImage) {
        _picImage = [[UIImageView alloc] init];
    }
    return _picImage;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel titleColour:TITLECOLOR
                              titleFount:15
                                pingfang:@"PingFang-SC-Regular"
                               alignment:NSTextAlignmentLeft
                               titleLine:1];
    }
    return _titleLab;
}
- (UIImageView *)pictureView {
    if (!_pictureView) {
        _pictureView = [[UIImageView alloc] init];
        _pictureView.hidden = YES;
    }
    return _pictureView;
}
- (UIView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIView alloc] init];
        _bgImageView.layer.cornerRadius = 5;
        _bgImageView.layer.masksToBounds = YES;
    }
    return _bgImageView;
}

@end










